package com.ftg.youx.listener;

import com.alibaba.fastjson2.JSON;
import com.ftg.youx.entity.SysEmp;
import com.ftg.youx.service.SysEmpService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * 监听器类
 *
 * @author 布衣
 */
@Component
@Slf4j
public class RabMqRevListener {

    @Resource
    SysEmpService sysEmpService;

    /**
     * 监听队列
     * @param msg
     */
    @RabbitListener(queues = "queue01")
    public void revMessage(String msg) {
        SysEmp sysEmp = JSON.parseObject(msg, SysEmp.class);
        try{
            sysEmpService.save(sysEmp);
            return ;
        }catch (Exception e){
            log.error("消息消费失败：{}", e.getMessage());
            return ;
        }
    }

}
